<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui 的主题样式  和  easyui 提供的图标样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css"  charset=UTF-8/>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css"  charset=UTF-8/>
<!-- 引入jquery 和  easyui.js   中文设置js-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js" charset=UTF-8></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js" charset=UTF-8></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js" charset=UTF-8></script>
</head>
<script type="text/javascript">
$(function() {
	//-----------------展现所有配送点信息--------------
	$("#dg").datagrid({
		url:'point',
		columns:[[   
		          {field:'ck',checkbox:true},
		          {field:'pid',title:'配送点编号',width:80},    
		          {field:'pname',title:'配送点名称',width:80},    
		          {field:'uid',title:'管理员编号',width:80},
		          {field:'pclass',title:'站点级别',width:30}, 
		          {field:'dname',title:'配送范围',width:80}, 
		      ]] ,
		      rownumbers:true,
		      pagination:true,
		      fitColumns:true,
		      pagePosition:'bottom',
		      pageSize:5,
		      pageList:[5,10],
		      toolbar: [{
		  		iconCls: 'icon-edit',
		  		text:'修改配送点信息',
				handler: function(){
				var  tea = $('#dg').datagrid('getSelections');
				if(tea.length==1){
					$("#point").dialog("open").dialog('setTitle', '修改配送点信息');
					$("#pid").val(tea[0].pid);
					$("#pname").val(tea[0].pname);
					$("#uid").val(tea[0].uid);
					 var p = tea[0].pclass;
					 $('#cc1').combobox('setValue', p);
					$("#save").linkbutton({
						onClick:function(){
							var pid= $("#pid").val();
							var pname= $("#pname").val();
							var uid= $("#uid").val();
							var pclass = $("#cc1").combo('getText');
							$.ajax({
								url:'updatepoint',
								type:'post',
								data:{'pid':pid,'pname':pname,'uid':uid,'pclass':pclass},
								datatype:'text',
								success:function(data){
									if(data=='1'){
										$.messager.alert('success','修改成功！','info');
										$('#dg').datagrid('reload');
										$("#point").dialog("close");
									}
								}
							})
						}
					})
				}else{
					$.messager.alert('error','请只选择一个！','info');
				}	
					//取消按钮
					$("#cancel").linkbutton({
						onClick:function(){
							$("#pid").val("");  // 清空修改输入框
							$("#pname").val("");
							$("#uid").val("");
							$('#cc1').combobox('setValue','');
							$("#point").dialog("close");
							$('#dg').datagrid('uncheckAll');
						}
					})

				}
			},'-',{
				iconCls: 'icon-remove',
				text:'删除配送点',
				handler: function(){
					var  teas = $('#dg').datagrid('getSelections');
					if(teas.length>0){
						$("#deletepoint").dialog("open").dialog('setTitle', '删除配送点');
						$("#yes").linkbutton({
							onClick:function(){
								var pids = [];
								for (var i = 0; i < teas.length; i++) {
									pids.push(teas[i].pid);
								}
								$.ajax({
									url:'deletepoints',
									type:'post',
									data:{'pids':pids,'i':i},
									traditional:true,
									datatype:'text',
									success:function(data){
										if(data=='1'){
											$.messager.alert('success','删除成功！','info');
											$('#dg').datagrid('reload');
											$("#deletepoint").dialog("close");
									}
								}
						 	 })
					 	  }
						})
					}else{
						$.messager.alert('MSG','请至少选择一个！','info');
					}
					$("#no").linkbutton({
						onClick:function(){
							$('#dg').datagrid('uncheckAll');
							$("#deletepoint").dialog("close");
							}
						})
				}
			}]
		})
});
</script>
<body>
<table id="dg"></table>
		<!------------修改弹出窗口------------>
		<div id="point" class="easyui-dialog" closable="false" closed="true" buttons="#dlg1-buttons" > 
		 <div  style="width: 250px;height: 150px;margin-top: 30px;margin-left: 30px">
        <input id="pid" name="pid" style="display: none"> 
        		<input id="pid" name="pid" style="display: none" />  
         	   配送点名称：<input id="pname" name="pname"  class="easyui-validatebox"  style="width:90px "/><br><br> 
           	   管理员编号：<input id="uid" name="uid"  class="easyui-validatebox"  style="width:90px "/><br><br>   
     		    站&nbsp;点&nbsp;级&nbsp;别：<select id="cc1" class="easyui-combobox" editable="false" name="cc1" size=2 style="width:90px;">   	  
												<option>主线站点</option>   
												<option>支线站点</option>     
											</select><br><br>
      </div>
       <div id="dlg1-buttons">
        <button id="save"  class="easyui-linkbutton"  iconcls="icon-save">确认</button>
        <a id="cancel" class="easyui-linkbutton"  iconcls="icon-cancel">取消</a>
        </div>
        </div>
<!-- 删除彈出窗口 -->
  		<div id="deletepoint" class="easyui-dialog" closable="false" closed="true" buttons="#dlg3-buttons" > 
		 <div  style="width: 100px;height: 30px;margin-top: 10px;margin-left: 30px">
	  		<p>确认删除吗？</p>
	  	 </div>
       <div id="dlg3-buttons">
        <button id="yes"  class="easyui-linkbutton"  iconcls="icon-save">确认</button>
        <a id="no" class="easyui-linkbutton"  iconcls="icon-cancel">取消</a>
        </div>
        </div>

</body>
</html>